<template>
	<view class="container home-bg home-pd home-h">
		<view class="list">
			<view @click="RelId=item.id" :class="{select:RelId==item.id}" v-for="(item,index) in list" :key="index"
				class="list-item flex flex-items-center flex-justify-center">
				<image v-if="RelId!==item.id" src="/src/static/images/center-store.png" mode=""></image>
				<image v-if="RelId==item.id" src="/src/static/images/center-store-select.png" mode=""></image>
				<view class="flex-1 name">{{item.relName}}</view>
				<uv-icon v-if="RelId==item.id" name="checkmark-circle-fill" color="#4776ED"></uv-icon>
			</view>
		</view>
		<view @click="login" class="button flex flex-justify-center flex-items-center">确认</view>
	</view>
</template>

<script setup>
	import {
		useAccountStore
	} from '@/store';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		getcentralWarehouse
	} from '@/api/login.js';
	onLoad(() => {
		init()
	})
	let list = ref([]);
	let RelId = ref("");
	const accountStore = useAccountStore();
	// let 
	async function init() {
		list.value = getList();
		if (list.value.length) {
			([{
				id: RelId.value = ''
			}] = list.value);
		} else {
			setTimeout(() => {
				uni.navigateBack()
			}, 1000)
		}

	}

	function getList() { 
		let {
			userRelRespVOList = []
		} = accountStore?.centralWarehouse || {};
		return userRelRespVOList;

	}

	function login() {
		uni.setStorageSync('Rel-Id', RelId.value);
		uni.switchTab({
			url: '/pages/goods/index'
		})
	}
</script>

<style lang="scss" scoped>
	@import 'index.scss';
</style>